package com.funo.logic.service;

import cn.hutool.json.JSONUtil;
import com.funo.logic.model.LogicConfig;
import com.funo.logic.response.HandleResult;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

/**
 * 逻辑节点配置服务
 * @since 2024年7月25日20:42:04
 */
@Service
public class LogicConfigService extends AbstractService {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    public LogicConfig getByBelongNodeId(String belongNodeId) {
        String cacheKey = getCacheKey(belongNodeId);
        String cacheValue = stringRedisTemplate.opsForValue().get(cacheKey);
        if (StringUtils.isBlank(cacheValue)) {
            return null;
        }
        return JSONUtil.toBean(cacheValue, LogicConfig.class);
    }

    @Override
    public String getCachePrefix() {
        return "logicConfig:";
    }
}
